package com.csd.action.manager;

import java.io.File;

import com.csd.excelimporter.TeacherImporter;
import com.csd.helper.ActionResult;
import com.csd.helper.Tool;
/**
 * 教师数据导入
 * @author 李书杰
 * <br> 创建时间2009-12-17
 *
 */
public class TeacherDataImportAction {
	
	public static final String DATA_TYPE_TEACHER = "teacherAccount";
	
	private String method;
	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}


	private String uploadFileName;	
	private File upload;
	private String type;
	private TeacherImporter importer;
	
	public String getUploadFileName() {
		return uploadFileName;
	}

	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	public File getUpload() {
		return upload;
	}

	public void setUpload(File upload) {
		this.upload = upload;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public TeacherImporter getImporter() {
		return importer;
	}

	public void setImporter(TeacherImporter importer) {
		this.importer = importer;
	}
   /***
    * 进行教师数据导入
    * @return
    */
	
	public String execute(){
		String result = ActionResult.fail;
		
		if(upload == null || upload.length()<=0)
		{
			return result;
		}
		String path = Tool.getPath();
		path = path + "temp" + File.separator + "temp.xls";		
		Tool.createFile( upload, path );
		
		if(type.equals(DATA_TYPE_TEACHER))
		{
			try{			
				importer.setInputFile(path);
				
				if(this.method != null && this.method.equals("1"))
				{
					importer.doThoroughlyImport();
				}else{
					importer.doRefreshImport();
				}
				
				result = ActionResult.success;
			}
			catch(Exception e)
			{
				System.out.println( e.getMessage() );
				e.printStackTrace();
			}
		}
		
		return result;
	}
}
